package util;

import java.sql.*;


//数据库配置类
public class DBTool {
	private static String driver = "com.mysql.jdbc.Driver";
	private static String dbURL = "jdbc:mysql://localhost/iyoga";
	private static String dbName="root";
	private static String dbPwd ="19950627";
	//获得数据库连接对象
	public static Connection getConnection(){
		Connection conn = null;
		try{
			Class.forName(driver);
			conn = DriverManager.getConnection(dbURL, dbName, dbPwd);
		}catch(SQLException ex){
			ex.printStackTrace();
		}catch(ClassNotFoundException ex){
			ex.printStackTrace();
		}
		return conn;
	}
	//关闭查询结果集
	public static void close(ResultSet rs){
		if(rs!=null){
			try{
				rs.close();
			}catch(SQLException ex){
				ex.printStackTrace();
			}
		}
	}
	//关闭预编译的语句对象
	public static void close(PreparedStatement prst){
		if(prst!=null){
			try{
				prst.close();
			}catch(SQLException ex){
				ex.printStackTrace();
			}
		}
	}
	//关闭连接对象
	public static void close(Connection conn){
		if(conn!=null){
			try{
				conn.close();
			}catch(SQLException ex){
				ex.printStackTrace();
			}
		}
	}
	//针对更新操作时候，关闭资源
	public static void close(PreparedStatement prst,Connection conn){
		close(prst);
		close(conn);
	}
	//针对查询操作时，关闭资源
	public static void close(ResultSet rs,PreparedStatement prst,Connection conn){
		close(rs);
		close(prst);
		close(conn);
	}
	
}
